/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.android.apps.mytracks.services.sensors.ant;

import com.dsi.ant.AntMesg;
import com.google.android.apps.mytracks.services.sensors.ant.AntPairer.PairingListener;
import com.google.android.testing.mocking.AndroidMock;
import com.google.android.testing.mocking.UsesMocks;

import android.test.AndroidTestCase;

/**
 * Tests {@link AntPairerSensorManager}
 *
 * @author Matthew Simmons
 */
public class AntPairerSensorManagerTest extends AndroidTestCase {
  @UsesMocks({PairingListener.class})
  public void testPairing() throws Exception {
    // TODO: Test the broadcast message which triggers the channel ID request.
    // We don't test it now because we don't have a good way to mock out the
    // getAntReceiver call.

    PairingListener mockPairingListener = AndroidMock.createMock(PairingListener.class);
    mockPairingListener.foundDevice((short) 0x1234);
    AndroidMock.replay(mockPairingListener);

    AntSensor sensor = AntSensor.SENSOR_HEART_RATE;
    byte[] message = { sensor.getChannelNumber(), 0x34, 0x12, 0x00, 0x00 };
    AntPairerSensorManager sensorManager = new AntPairerSensorManager(getContext(), sensor,
        mockPairingListener);
    sensorManager.handleOneMessage(sensor.getChannelNumber(), AntMesg.MESG_CHANNEL_ID_ID,
        message);

    AndroidMock.verify(mockPairingListener);
  }
}
